package org.linphone.utils;

import android.annotation.SuppressLint;
import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;

import static android.content.Context.KEYGUARD_SERVICE;

public class ScreenWakeUtils {
    /**唤醒屏幕
     * hu
     * @param context
     */
    public static void wakeUpAndUnlock(Context context) {

        PowerManager powerManager = (PowerManager) context
                .getSystemService(Context.POWER_SERVICE);
        //检查屏幕
        if (powerManager != null) {
            boolean screenOn = powerManager.isScreenOn();
            if (!screenOn) {
                // 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
                @SuppressLint("InvalidWakeLockTag") PowerManager.WakeLock wl = powerManager.newWakeLock(
                        PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
                wl.acquire(10000); // 点亮屏幕
                wl.release(); // 释放

                // 屏幕解锁
                KeyguardManager keyguardManager = (KeyguardManager)context
                        .getSystemService(KEYGUARD_SERVICE);
                KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");
                // 屏幕锁定
                keyguardLock.reenableKeyguard();
                keyguardLock.disableKeyguard(); // 解锁
            }
        }
    }
}
